/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Detail.java
 *
 * Created on 05.12.2011., 14.36.54
 */

package tok.predmeta;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author mega
 */
public class Detail extends javax.swing.JFrame {
   
    /** Creates new form Detail */
    public Detail() {
        initComponents();
        
        

             // Load the JDBC driver
        String driverName = "com.mysql.jdbc.Driver"; // MySQL  JDBC driver
        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Pretraga.class.getName()).log(Level.SEVERE, null, ex);
        }

// Create a connection to the database
        String serverName = "192.168.88.10";
        String mydatabase = "tok_predmeta";
        String url = "jdbc:mysql://" + serverName + "/" + mydatabase + "?useUnicode=true&characterEncoding=utf8"; // a JDBC url
        String username = "tokpred";
        String password = "Lx3sAQdnYJFTxBhs";
       System.out.println("Broj predemta "+Reminder.Brpredmeta);
        try {
            java.sql.Connection connection = DriverManager.getConnection(url, username, password);
            java.sql.PreparedStatement s = connection.prepareStatement("SELECT *  FROM state where sifra="+Tabela.Brpredmeta+" ");

            s.executeQuery();

            ResultSet rs = s.getResultSet();
             ArrayList al = new ArrayList();
             while (rs.next()) {
                String sifra = rs.getString("stanje_predmeta");
                if(sifra.equals("01")){
                    sifra = "У пријемној канцеларији";
                }else if(sifra.equals("02")){
                     sifra = "У судској управи";

                } else if (sifra.equals("03")) {
                     sifra = "На изјашњењу код судије";

                } else if (sifra.equals("04")) {
                     sifra = "На изјашњењу ";

                 }else if (sifra.equals("05")) {
                     sifra = "На потпису за експедицију ";

                 }else if (sifra.equals("06")) {
                     sifra = "У одељењу за експедицију ";

                  }else if (sifra.equals("07")) {
                     sifra = "Експедован ";

                  }else if (sifra.equals("08")) {
                     sifra = "Експедован - уручен";

                  }else if (sifra.equals("09")) {
                     sifra = "Експедован - неуручен";

                  }else if (sifra.equals("10")) {
                     sifra = "Враћена експедиција ";

                }else{
                     sifra = "Непознато стање";
                }

                
                String date = rs.getString("date");
                 String korisnik = rs.getString("korisnik");
                 al.add(sifra+" Дана :"+ date + " Уписао корисник : "+korisnik);

            }

             String red ="ДЕТАЉНО КРЕТАЊЕ ПРЕДМЕТА  : \n\n\n";
              Iterator<String> itr = al.iterator();
            while (itr.hasNext()) {

               red += itr.next()+ "\n";

            }

               jTextArea1.setText(red);

         } catch (SQLException ex) {
            Logger.getLogger(Pretraga.class.getName()).log(Level.SEVERE, null, ex);

        }
    
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jLabel1.setFont(new java.awt.Font("Arial", 0, 18));
        jLabel1.setText("Детаљи предмета");

        jButton1.setText("Назад");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jButton1)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 633, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(28, 28, 28)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(32, 32, 32))
        );

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
//        Reminder R=new Reminder();
//        dispose();
//        R.setVisible(true);
        Tabela R=new Tabela();
        dispose();
        R.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Detail().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables






}
